
//加载省数据
function loadProvince() {
    var proHtml = '';
    for (var i = 0; i < areaData.length; i++) {
    //    proHtml += '<option value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i + '">' + areaData[i].provinceName + '</option>';
        if((areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i)==array[0]){
            proHtml += '<option selected="selected" value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i + '">' + areaData[i].provinceName + '</option>';
        }else{
            proHtml += '<option value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i + '">' + areaData[i].provinceName + '</option>';
        }
    }

    //初始化省数据
    $form.find('select[name=province]').append(proHtml);
    form.render();
    form.on('select(province)', function(data) {
        $form.find('select[name=area]').html('<option value="">请选择县/区</option>').parent().hide();
        var value = data.value;
        var d = value.split('_');
        var code = d[0];
        var count = d[1];
        var index = d[2];
        if (count > 0) {
            loadCity(areaData[index].mallCityList);
        } else {
            $form.find('select[name=city]').parent().hide();
        }
    });
}
//加载市数据
function loadCity(citys) {
    var cityHtml = '';
    for (var i = 0; i < citys.length; i++) {
    //    cityHtml += '<option value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i + '">' + citys[i].cityName + '</option>';
        if((citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i)==array[1]){
            cityHtml += '<option selected value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i + '">' + citys[i].cityName + '</option>';
        }else{
            cityHtml += '<option value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i + '">' + citys[i].cityName + '</option>';
        }
    }
    $form.find('select[name=city]').html(cityHtml).parent().show();
    form.render();
    form.on('select(city)', function(data) {
        var value = data.value;
        var d = value.split('_');
        var code = d[0];
        var count = d[1];
        var index = d[2];
        if (count > 0) {
            loadArea(citys[index].mallAreaList);
        } else {
            $form.find('select[name=area]').parent().hide();
        }
    });
}
//加载县/区数据
function loadArea(areas) {
    var areaHtml = '';
    for (var i = 0; i < areas.length; i++) {
        if (array[2]==(areas[i].areaCode)){
            areaHtml += '<option selected value="' + areas[i].areaCode + '">' + areas[i].areaName + '</option>';

        }else {
            areaHtml += '<option value="' + areas[i].areaCode + '">' + areas[i].areaName + '</option>';

        }
      //  areaHtml += '<option value="' + areas[i].areaCode + '">' + areas[i].areaName + '</option>';

    }
    $form.find('select[name=area]').html(areaHtml).parent().show();
    form.render();
    form.on('select(area)', function(data) {
        //console.log(data);
    });
}
function selectProvince() {
    var value = array[0];
    var d = value.split('_');
    var code = d[0];
    var count = d[1];
    var index = d[2];
    var value1 = array[1];
    var d1 = value.split('_');
    var code1 = d[0];
    var count1 = d[1];
    var index1 = d[2];
    for (var i = 0; i < areaData.length; i++) {
        if (array[0]==(areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i)){
            $("#suozai").append(areaData[i].provinceName)
        }
    }
    for (var j = 0; j < areaData[index].mallCityList.length; j++) {
        //alert(array[1]+"=="+areaData[index].mallCityList[j].cityName+"=="+(areaData[index].mallCityList[j].cityCode + '_' + areaData[index].mallCityList[j].mallAreaList.length + '_' + j))
        if (array[1]==(areaData[index].mallCityList[j].cityCode + '_' + areaData[index].mallCityList[j].mallAreaList.length + '_' + j)){
            //alert(areaData[index].mallCityList[j].cityName);
            $("#suozai").append(areaData[index].mallCityList[j].cityName)
        }
    }

    for (var k = 0; k < areaData[index].mallCityList[index1].mallAreaList.length; k++) {
        if (array[2]==( areaData[index].mallCityList[index1].mallAreaList[k].areaCode)){
            $("#suozai").append(areaData[index].mallCityList[index1].mallAreaList[k].areaName)
        }

    }
}